//
//  ClubIntegralView.swift
//  77Club
//
//  Created by Apple on 2024/9/11.
//

import UIKit

class ClubMineSigninCell: UICollectionViewCell {
    
    private let iconImageView = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).end()
    private let timeLabel = c_make_ex(UIButton.self)
        .color("#AEB0B3").color("#2E3033", state: .selected).font(12.font_semiBold).end()
    private let rectView = c_make_ex(UIView.self)
        .corner(3).bgColor("#E4E5E6").end()
    private let preLineView = c_make_ex(UIView.self).end()
    private let lastLineView = c_make_ex(UIView.self).end()
    
    var model: ClubMySignDateModel? {
        didSet{
            guard let md = model else { return }
            let today = Date().toTimeStamp()
            let todayString = Date().toString()
            timeLabel.isSelected = md.time2 * 1000 >= today
            let titleArray = md.time.components(separatedBy: "-")
            if md.time == todayString {
                timeLabel.isSelected = true
                timeLabel.setTitle("今天", for: .normal)
            }else{
                let titleString = titleArray[1] + "." + titleArray[2]
                timeLabel.setTitle(titleString, for: .normal)
            }
            if md.time2 * 1000 > today {
                rectView.backgroundColor = "#E4E5E6".toColor
                preLineView.backgroundColor = "#E4E5E6".toColor
                lastLineView.backgroundColor = "#E4E5E6".toColor
            } else if md.time == todayString {
                rectView.backgroundColor = "#D23C44".toColor
                preLineView.backgroundColor = "#D23C44".toColor
                lastLineView.backgroundColor = "#E4E5E6".toColor
            } else {
                rectView.backgroundColor = "#D23C44".toColor
                preLineView.backgroundColor = "#D23C44".toColor
                lastLineView.backgroundColor = "#D23C44".toColor
            }
            if md.time2 * 1000 > today {
                iconImageView.image = "Mine_signin_hongbao".toImage   
                let number = Int(titleArray[2]) ?? 0
                if number % 7 == 0 {
                    iconImageView.image = "Mine_signin_gift".toImage
                }
            }else{
                if md.sign == "1"{
                    iconImageView.image = "Mine_signin_signed".toImage
                }else{
                    iconImageView.image = "Mine_signin_notSign".toImage
                }
            }
            
        }
        
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentView.backgroundColor = .clear
        backgroundColor = .clear
        
        contentView.subviews{
            iconImageView
            rectView
            preLineView
            lastLineView
            timeLabel
        }

        iconImageView.leading(6.0.Scale).trailing(6.0.Scale).top(0).size(36.0.Scale)
        rectView.size(6.0.Scale)
        rectView.Top == iconImageView.Bottom + 11.0.Scale
        rectView.CenterX == iconImageView.CenterX
        preLineView.leading(0).height(2)
        preLineView.Trailing == rectView.Leading
        preLineView.CenterY == rectView.CenterY
        lastLineView.trailing(0).height(2)
        lastLineView.Leading == rectView.Trailing
        lastLineView.CenterY == rectView.CenterY
        timeLabel.height(10.0.Scale).leading(0).trailing(0)
        timeLabel.Top == rectView.Bottom + 27.0.Scale
        
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

//MARK: 签到活动规则
class ClubMineSigninRuleView: UIView {
    
    private let bgView = c_make_ex(UIImageView.self)
        .image("Mine_signin_ruleBg").mode(.scaleToFill).end()
    private let titleLabel = c_make_ex(UILabel.self)
        .color("#1A1A1A").font(14.font_semiBold)
        .text("活动规则").end()
    private let contentLabel = c_make_ex(UILabel.self)
        .color("#47494D").font(12.font_semiBold).line(0).end()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = .clear
        
        subviews{
            bgView.subviews{
                titleLabel
                contentLabel
            }
        }
        
        bgView.leading(12.0.Scale).trailing(12.0.Scale).top(0).height(145.0.Scale)
        titleLabel.leading(12.0.Scale).top(16.0.Scale)
        contentLabel.leading(12.0.Scale).trailing(12.0.Scale)
        contentLabel.Top == titleLabel.Bottom + 12.0.Scale
        // 创建一个 NSMutableAttributedString
        let attributedString = NSMutableAttributedString(string: "1.连续签到次数越多 获得积分越多,断签重新开始单日积分+10 封顶。\n2.积分可在积分商城兑换奖品。\n3.本次活动最终解释权本平台所有。")
        // 创建一个 NSMutableParagraphStyle 设置行间距
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = 6  // 设置行间距
        // 将段落样式应用到整个文本
        attributedString.addAttribute(.paragraphStyle, value: paragraphStyle, range: NSMakeRange(0, attributedString.length))
        // 设置 UILabel 的 attributedText 属性
        contentLabel.attributedText = attributedString
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
